package com.mrd.gtimpframe.service.impl;

import com.mrd.gtimpframe.entity.GoodsCode;
import com.mrd.gtimpframe.entity.GoodsCodeKey;
import com.mrd.gtimpframe.repository.GoodsCodeMapper;
import com.mrd.gtimpframe.service.GoodsCodeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by dusy on 2017/7/27.
 */
@Service
public class GoodsCodeServiceImpl implements GoodsCodeService {
    @Autowired
    private GoodsCodeMapper goodsCodeMapper;

    @Override
    public int deleteByPrimaryKey(GoodsCodeKey key) {
        return goodsCodeMapper.deleteByPrimaryKey(key);
    }

    @Override
    public int insert(GoodsCode record) {
        return goodsCodeMapper.insert(record);
    }

    @Override
    public int insertSelective(GoodsCode record) {
        return goodsCodeMapper.insertSelective(record);
    }

    @Override
    public GoodsCode selectByPrimaryKey(GoodsCodeKey key) {
        return goodsCodeMapper.selectByPrimaryKey(key);
    }

    @Override
    public int updateByPrimaryKeySelective(GoodsCode record) {
        return goodsCodeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(GoodsCode record) {
        return goodsCodeMapper.updateByPrimaryKey(record);
    }

    /**
     * 根据非null属性查询，codeT、codeS、gName、unit1、unit2、goodsMode为模糊查询
     */
    @Override
    public List<GoodsCode> selectSelective(GoodsCode params) {
        return goodsCodeMapper.selectSelective(params);
    }


    /**
     * 新增或修改Selective
     */
    @Override
    public int saveOrUpdate(GoodsCode goodsCode) {
        if (this.selectByPrimaryKey(goodsCode) == null) {
            return this.insertSelective(goodsCode);
        } else {
            return this.updateByPrimaryKeySelective(goodsCode);
        }
    }
}
